<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>积分规则设置</title>
    <link rel="stylesheet" type="text/css" href="../lib/laydate.css"/>
    <link rel="stylesheet" type="text/css" href="../lib/pagination/style/pagination.css"/>
    <link rel="stylesheet" type="text/css" href="../css/base.css"/>
    <script type="text/javascript" src="../js/news/jquery-1.9.1.js"></script>
    <script src="../js/news/page.js"></script>
    <script src="../lib/laydate.js"></script>
    <script src="../js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../lib/layer/layer.js?20201106"></script>
    <link rel="stylesheet" type="text/css" href="/css/commonTheme/${sessionScope.InterfaceModel}/commonTheme.css"/>
    <style>
        a{
            text-decoration: none;
            color: #207bd6;
        }
        .head{
            height: 45px;
        }
        .divTable{
            width: 60%;
            margin: 20px auto;
        }
        .divTable table{
            width: 100%;
        }
        .divTable table tr th{
            padding: 8px;
            font-size: 11pt;
            color: #2F5C8F;
        }
        .navigation{
            float: none;
            border-bottom: #ccc 1px solid;
            height: 45px;
        }
        .navigation .left{
            line-height: 45px;
        }
        .navigation .left img{
            margin-top: 6px;
        }
        .divBtn{
            border-radius: 4px;
        }
        .divNew{
            width: 100%;
        }
        .divNew table{
            width: 82%;
            margin: 20px auto;
        }
        .divNew table tr{
            border: none;
        }
        .divNew table tr td:first-of-type{
            width: 60px;
        }
        .divNew table tr td input{
            width: 220px;
            height: 28px;
            border-radius: 5px;
            padding-left: 5px;
        }
        .divTable table tr td{
            text-align: center;
        }

    </style>
</head>

<body>
<div class="bx">
    <%--<div class="head w clearfix">--%>
        <%--<ul class="index_head">--%>
            <%--&lt;%&ndash;<li data_id="0" data-num="0"><span class="one headli1_1"><fmt:message code="vote.th.LibraryManagement"/></span><img class="headli1_2" src="../img/twoth.png" alt=""/></li>&ndash;%&gt;--%>
            <%--<li data_id="1" data-num="2"><span class="headli">积分规则设置</span></li>--%>

        <%--</ul>--%>
    <%--</div>--%>
    <div class="mainCon">
        <div class="navigation" style="display: block;">
            <div class="left" style="margin-left: 30px">
                <img src="/img/commonTheme/${sessionScope.InterfaceModel}/icon_manageRollRoom.png">
                <div class="news">积分规则设置</div>
            </div>
            <div class="divBtn">
                <img src="../../img/mywork/newbuildworjk.png" alt="" style="margin-left: 6px;margin-top: -4px;">
                <span style="font-size: 11pt;">新建积分</span>
            </div>
        </div>
        <div class="divTable">
            <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse">
                <thead>
                    <tr>
                        <th>序号</th>
                        <th>积分项</th>
                        <th>积分</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody id="trList">

                </tbody>
            </table>
            <div class="right">
                <!-- 分页按钮-->
                <div class="M-box3" id="dbgz_page"></div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {

        init($('#trList'));
//        新建
        $('.divBtn').click(function () {
            layer.open({
                type: 1,
                title:['新建积分', 'background-color:#2b7fe0;color:#fff;'],
                area: ['400px', '300px'],
                shadeClose: true, //点击遮罩关闭
                btn: ['确定', '取消'],
                content:'<div class="divNew">' +
                '<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse">' +
                '<tr>' +
                '<td>序号：</td>' +
                '<td><input type="text" name="inno" value=""></td>' +
                '</tr>' +
                '<tr>' +
                '<td>积分项：</td>' +
                '<td><input type="text" name="integralterm" value=""></td>' +
                '</tr>' +
                '<tr>' +
                '<td>积分：</td>' +
                '<td><input type="text" name="score" value=""></td>' +
                '</tr>' +
                '</table>' +
                '</div>',
                yes:function (index) {
                    $.ajax({
                        type:'post',
                        url:'/Integral/addIntegral',
                        dataType:'json',
                        data:{
                            inno:$('input[name="inno"]').val(),
                            integralterm:$('input[name="integralterm"]').val(),
                            score:$('input[name="score"]').val(),
                        },
                        success:function (res) {
                            if(res.flag){
                                $.layerMsg({content:'新建成功！',icon:1})
                                layer.close(index);
                                init($('#trList'));
                            }else{
                                $.layerMsg({content:'新建失败！',icon:2})
                            }
                        }
                    })

                },
            })
        })
//        编辑
        $('#trList').on('click','.editDiv',function () {
            var dataId=$(this).parents('tr').attr('data-id');
            layer.open({
                type: 1,
                title:['新建积分', 'background-color:#2b7fe0;color:#fff;'],
                area: ['400px', '300px'],
                shadeClose: true, //点击遮罩关闭
                btn: ['确定', '取消'],
                content:'<div class="divNew">' +
                '<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse">' +
                '<tr>' +
                '<td>序号：</td>' +
                '<td><input type="text" name="inno" value=""></td>' +
                '</tr>' +
                '<tr>' +
                '<td>积分项：</td>' +
                '<td><input type="text" name="integralterm" value=""></td>' +
                '</tr>' +
                '<tr>' +
                '<td>积分：</td>' +
                '<td><input type="text" name="score" value=""></td>' +
                '</tr>' +
                '</table>' +
                '</div>',
                success:function () {
                    $.ajax({
                        type:'get',
                        url:'/Integral/selectById',
                        dataType:'json',
                        data:{id:dataId},
                        success:function (res) {
                            var datas=res.object;
                            $('input[name="inno"]').val(datas.inno);
                            $('input[name="integralterm"]').val(datas.integralterm);
                            $('input[name="score"]').val(datas.score);
                        }
                    })
                },
                yes:function (index) {
                    $.ajax({
                        type:'post',
                        url:'/Integral/updateIntegral',
                        dataType:'json',
                        data:{
                            inno:$('input[name="inno"]').val(),
                            integralterm:$('input[name="integralterm"]').val(),
                            score:$('input[name="score"]').val(),
                            id:dataId
                        },
                        success:function (res) {
                            if(res.flag){
                                $.layerMsg({content:'新建成功！',icon:1})
                                layer.close(index);
                                init($('#trList'));
                            }else{
                                $.layerMsg({content:'新建失败！',icon:2})
                            }
                        }
                    })

                },
            })
        })
//        删除
        $('#trList').on('click','.deleteData',function () {
            var dataId=$(this).parents('tr').attr('data-id');
            layer.confirm('确定要删除吗？', {
                btn: ['确定','取消'], //按钮
                title:"删除"
            }, function(){
                //确定删除，调接口
                $.ajax({
                    type:'post',
                    url:'/Integral/deleteIntegralId',
                    dataType:'json',
                    data:{id:dataId},
                    success:function(res){
                        if(res.flag){
                            layer.msg('删除成功！', { icon:6,time:2000});
                            init($('#trList'));
                        }else {
                            layer.msg('删除失败！', { icon:5,time:2000});
                        }
                    }
                })

            }, function(){
                layer.closeAll();
            });
        })
    })
    function init(element) {
        var ajaxPage={
            data:{
                page:1,//当前处于第几页
                pageSize:10,//一页显示几条
                useFlag:true
            },
            page:function () {
                element.find('tr').remove();
                var me=this;
                $.ajax({
                    type:'get',
                    url:'/Integral/selectIntegral',
                    dataType:'json',
                    data:me.data,
                    success:function(res) {
                        var datas=res.obj;
                        var str='';
                        for(var i=0;i<datas.length;i++){
                            str+='<tr data-id="'+datas[i].id+'">' +
                                '<td>'+datas[i].inno+'</td>' +
                                '<td>'+datas[i].integralterm+'</td>' +
                                '<td>'+datas[i].score+'</td>' +
                                '<td><a href="javascript:;" class="editDiv" style="margin-right: 10px;">编辑</a><a href="javascript:;" class="deleteData">删除</a></td>' +
                                '</tr>'
                        }

                        element.append(str);
                        me.pageTwo(res.totleNum,me.data.pageSize,me.data.page)
                    }
                })

            },
            pageTwo:function (totalData, pageSize,indexs) {
                var mes=this;
                $('#dbgz_page').pagination({
                    totalData: totalData,
                    showData: pageSize,
                    jump: true,
                    coping: true,
                    homePage:'',
                    endPage: '',
                    current:indexs||1,
                    callback: function (index) {
                        mes.data.page=index.getCurrent();
                        mes.page();
                    }
                });
            }
        }
        ajaxPage.page();
    }

</script>
</body>
</html>
